﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 一个用于消息弹出显示的类
	/// </summary>
	// Token: 0x02000186 RID: 390
	public partial class FormPopup : Form
	{
		/// <summary>
		/// 新增一个显示的弹出窗口
		/// </summary>
		/// <param name="form"></param>
		// Token: 0x06001FBD RID: 8125 RVA: 0x0009A2E8 File Offset: 0x000984E8
		private static void AddNewForm(FormPopup form)
		{
			try
			{
				foreach (FormPopup formPopup in FormPopup.FormsPopup)
				{
					formPopup.LocationUpMove();
				}
				FormPopup.FormsPopup.Add(form);
			}
			catch (Exception ex)
			{
				Console.WriteLine(SoftBasic.GetExceptionMessage(ex));
			}
		}

		/// <summary>
		/// 重置所有弹出窗口的位置
		/// </summary>
		// Token: 0x06001FBE RID: 8126 RVA: 0x0009A36C File Offset: 0x0009856C
		private static void ResetLocation()
		{
			try
			{
				for (int i = 0; i < FormPopup.FormsPopup.Count; i++)
				{
					FormPopup.FormsPopup[i].LocationUpMove(FormPopup.FormsPopup.Count - 1 - i);
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine(SoftBasic.GetExceptionMessage(ex));
			}
		}

		/// <summary>
		/// 实例化一个窗口信息弹出的对象
		/// </summary>
		// Token: 0x06001FBF RID: 8127 RVA: 0x0009A3DC File Offset: 0x000985DC
		public FormPopup()
		{
			this.InitializeComponent();
		}

		/// <summary>
		/// 实例化一个窗口信息弹出的对象
		/// </summary>
		/// <param name="infotext">需要显示的文本</param>
		// Token: 0x06001FC0 RID: 8128 RVA: 0x0009A418 File Offset: 0x00098618
		public FormPopup(string infotext)
		{
			this.InitializeComponent();
			this.InfoText = infotext;
		}

		/// <summary>
		/// 实例化一个窗口信息弹出的对象
		/// </summary>
		/// <param name="infotext">需要显示的文本</param>
		/// <param name="infocolor">文本的颜色</param>
		// Token: 0x06001FC1 RID: 8129 RVA: 0x0009A468 File Offset: 0x00098668
		public FormPopup(string infotext, Color infocolor)
		{
			this.InitializeComponent();
			this.InfoText = infotext;
			this.InfoColor = infocolor;
		}

		/// <summary>
		/// 实例化一个窗口信息弹出的对象
		/// </summary>
		/// <param name="infotext">需要显示的文本</param>
		/// <param name="infocolor">文本的颜色</param>
		/// <param name="existTime">指定窗口多少时间后消失，单位毫秒</param>
		// Token: 0x06001FC2 RID: 8130 RVA: 0x0009A4C0 File Offset: 0x000986C0
		public FormPopup(string infotext, Color infocolor, int existTime)
		{
			this.InitializeComponent();
			this.InfoText = infotext;
			this.InfoColor = infocolor;
			this.InfoExistTime = existTime;
		}

		// Token: 0x17000692 RID: 1682
		// (get) Token: 0x06001FC3 RID: 8131 RVA: 0x0009A51F File Offset: 0x0009871F
		// (set) Token: 0x06001FC4 RID: 8132 RVA: 0x0009A527 File Offset: 0x00098727
		private string InfoText { get; set; } = "This is a test message";

		// Token: 0x17000693 RID: 1683
		// (get) Token: 0x06001FC5 RID: 8133 RVA: 0x0009A530 File Offset: 0x00098730
		// (set) Token: 0x06001FC6 RID: 8134 RVA: 0x0009A538 File Offset: 0x00098738
		private Color InfoColor { get; set; } = Color.DimGray;

		// Token: 0x17000694 RID: 1684
		// (get) Token: 0x06001FC7 RID: 8135 RVA: 0x0009A541 File Offset: 0x00098741
		// (set) Token: 0x06001FC8 RID: 8136 RVA: 0x0009A549 File Offset: 0x00098749
		private int InfoExistTime { get; set; } = -1;

		// Token: 0x06001FC9 RID: 8137 RVA: 0x0009A554 File Offset: 0x00098754
		private void FormPopup_Load(object sender, EventArgs e)
		{
			this.label1.Text = this.InfoText;
			this.label1.ForeColor = this.InfoColor;
			this.label2.Text = StringResources.Language.Close;
			FormPopup.AddNewForm(this);
			int x = Screen.PrimaryScreen.WorkingArea.Right - base.Width;
			int y = Screen.PrimaryScreen.WorkingArea.Bottom - base.Height;
			base.Location = new Point(x, y);
			FormPopup.AnimateWindow(base.Handle, 1000, 262152);
			base.TopMost = true;
			bool flag = this.InfoExistTime > 100;
			if (flag)
			{
				this.time = new Timer();
				this.time.Interval = this.InfoExistTime;
				this.time.Tick += delegate(object <p0>, EventArgs <p1>)
				{
					bool isHandleCreated = base.IsHandleCreated;
					if (isHandleCreated)
					{
						this.time.Dispose();
						FormPopup.AnimateWindow(base.Handle, 1000, 589824);
						base.Close();
					}
				};
				this.time.Start();
			}
		}

		/// <summary>
		/// 窗体的位置进行向上调整
		/// </summary>
		// Token: 0x06001FCA RID: 8138 RVA: 0x0009A654 File Offset: 0x00098854
		public void LocationUpMove()
		{
			base.Location = new Point(base.Location.X, base.Location.Y - base.Height);
		}

		/// <summary>
		/// 窗体的位置进行向上调整
		/// </summary>
		// Token: 0x06001FCB RID: 8139 RVA: 0x0009A694 File Offset: 0x00098894
		public void LocationUpMove(int index)
		{
			base.Location = new Point(base.Location.X, Screen.PrimaryScreen.WorkingArea.Bottom - base.Height - index * base.Height);
		}

		// Token: 0x06001FCC RID: 8140 RVA: 0x0009A6E0 File Offset: 0x000988E0
		private void FormPopup_Closing(object sender, FormClosingEventArgs e)
		{
			try
			{
				this.time.Enabled = false;
				FormPopup.FormsPopup.Remove(this);
				FormPopup.ResetLocation();
			}
			catch (Exception ex)
			{
				Console.WriteLine(SoftBasic.GetExceptionMessage(ex));
			}
		}

		// Token: 0x06001FCD RID: 8141
		[DllImport("user32")]
		private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

		// Token: 0x06001FCE RID: 8142 RVA: 0x0009A734 File Offset: 0x00098934
		private void FormPopup_Paint(object sender, PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			graphics.FillRectangle(Brushes.SkyBlue, new Rectangle(0, 0, base.Width - 1, 30));
			StringFormat format = new StringFormat
			{
				Alignment = StringAlignment.Near,
				LineAlignment = StringAlignment.Center
			};
			graphics.DrawString(StringResources.Language.MessageTip, this.label2.Font, Brushes.DimGray, new Rectangle(5, 0, base.Width - 1, 30), format);
			graphics.DrawRectangle(Pens.DimGray, 0, 0, base.Width - 1, base.Height - 1);
		}

		// Token: 0x06001FCF RID: 8143 RVA: 0x0009A7D2 File Offset: 0x000989D2
		private void label2_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		// Token: 0x06001FD0 RID: 8144 RVA: 0x0009A7DC File Offset: 0x000989DC
		private void label2_MouseEnter(object sender, EventArgs e)
		{
			SoftAnimation.BeginBackcolorAnimation(this.label2, Color.Tomato, 100);
		}

		// Token: 0x06001FD1 RID: 8145 RVA: 0x0009A7F2 File Offset: 0x000989F2
		private void label2_MouseLeave(object sender, EventArgs e)
		{
			SoftAnimation.BeginBackcolorAnimation(this.label2, Color.MistyRose, 100);
		}

		// Token: 0x04000768 RID: 1896
		private static List<FormPopup> FormsPopup = new List<FormPopup>();

		// Token: 0x0400076C RID: 1900
		private Timer time = null;

		// Token: 0x0400076D RID: 1901
		private const int AW_HOR_POSITIVE = 1;

		// Token: 0x0400076E RID: 1902
		private const int AW_HOR_NEGATIVE = 2;

		// Token: 0x0400076F RID: 1903
		private const int AW_VER_POSITIVE = 4;

		// Token: 0x04000770 RID: 1904
		private const int AW_VER_NEGATIVE = 8;

		// Token: 0x04000771 RID: 1905
		private const int AW_CENTER = 16;

		// Token: 0x04000772 RID: 1906
		private const int AW_HIDE = 65536;

		// Token: 0x04000773 RID: 1907
		private const int AW_ACTIVE = 131072;

		// Token: 0x04000774 RID: 1908
		private const int AW_SLIDE = 262144;

		// Token: 0x04000775 RID: 1909
		private const int AW_BLEND = 524288;
	}
}
